package com.yzw.endecoderfixed;

/**
 * @Author: YangZhenWei
 * @PROJECT_NAME: nettyTeach
 * @DESCRIPTION: 通用工具类
 * @USER: root
 * @DATE: 2023/2/9 23:17
 **/
public class CommonUtils {
    public static final int FIXEDLENGTHFRAME_LENGTH = 5; // 定长解码器 FIXEDLENGTHFRAME 对应的消息长度

    /**
     * 获取定长的字符串
     *
     * @param str 输入字符串
     * @param assignLength 指定长度
     * @return 补足的字符串
     */
    public static String formatString(String str, int assignLength) {
        int intStrLen = 0;
        if (str != null) {
            intStrLen = str.length();
        }
        if (intStrLen >= assignLength) { // 如果和制定长度一致，则直接返回
            return str;
        } else // 右补空格
        {
            String strSpace = "";
            for (int i = 0, num = assignLength - intStrLen; i < num; i++) {

                strSpace = strSpace + " ";
            }
            return str + strSpace;

        }
    }
}
